//
//  UserEditEmotionalCell.m
//  CheekiOS
//
//  Created by mac on 2017/7/5.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "UserEditEmotionalCell.h"

@interface UserEditEmotionalCell ()

@property (nonatomic, strong)UILabel *nameLab;
@property (nonatomic, strong)NSIndexPath *indexpath;

@end

@implementation UserEditEmotionalCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath*)indexPath {

    static NSString *UserEditEmotionalCellIdent = @"UserEditEmotionalCellIdent";
    UserEditEmotionalCell *cell = [tableView dequeueReusableCellWithIdentifier:UserEditEmotionalCellIdent];
    if (!cell) {
        cell = [[UserEditEmotionalCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:UserEditEmotionalCellIdent];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.indexpath = indexPath;
    return cell;
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.nameLab = [[UILabel alloc] init];
        self.nameLab.font = FontP(15);
        self.nameLab.textColor = [UIColor blackColor];
        self.nameLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:self.nameLab];
        [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15);
            make.height.equalTo(self);
            make.width.mas_equalTo(100);
        }];

        self.button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.button setBackgroundImage:[UIImage imageNamed:@"bjzl_emotion_choice_button"] forState:UIControlStateNormal];
        [self.button setBackgroundImage:[UIImage imageNamed:@"bjzl_emotion_choice_button_p"] forState:UIControlStateSelected];
        [self addSubview:self.button];
        [self.button addTarget:self action:@selector(buttonActionClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-25);
            make.height.mas_equalTo(24);
            make.width.mas_equalTo(24);
            make.top.mas_equalTo(15.5);
        }];
        
    }
    
    return self;
}

- (void)setModel:(UserEditEmotinalModel *)model{

    _model = model;
    self.nameLab.text = model.title;
    self.button.tag = _indexpath.row;

    self.button.selected = model.isSelect;
}

- (void)buttonActionClick:(UIButton *)button{
 
    if ([self.delegate respondsToSelector:@selector(userEditEmotinalCell:clickBtn:)]) {
        [self.delegate userEditEmotinalCell:self clickBtn:button];
    }

}

@end
